package com.base.service.impl;

import java.util.List;

import com.base.bean.Goodsman;
import com.base.service.GoodsmanService;
import com.common.util.AbstractManager;
import com.common.util.PagerModel;

public class GoodsmanServiceImpl extends AbstractManager implements
		GoodsmanService {

	public void addGoodsman(Goodsman goodsman) {
		String hql = "select nvl(max(goodmanno),0) from Goodsman";
		
		long goodmanno = 0l;
		goodmanno = (Long) this.getHibernateTemplate().find(hql).get(0);
		goodmanno += 1l;
		
		goodsman.setGoodmanno(goodmanno);
		this.getHibernateTemplate().save(goodsman);
	}

	@SuppressWarnings("unchecked")
	public List<Goodsman> findAllGoodsman() {
		String hql = "from Goodsman order by goodmanno";
		return this.getHibernateTemplate().find(hql);
	}

	public Goodsman findGoodsman(long goodmanno) {
		return (Goodsman) this.getHibernateTemplate().load(Goodsman.class, goodmanno);
	}

	public PagerModel findGoodsmanForPager() {
		String hql = "from Goodsman order by goodmanno";
		return searchPaginated(hql);
	}

	public void removeGoodsman(long goodmanno) {
		Goodsman goodsman = null;
		
		goodsman = (Goodsman) this.getHibernateTemplate().load(Goodsman.class, goodmanno);
		if(goodsman != null)
			this.getHibernateTemplate().delete(goodsman);
	}

	public void updateGoodsman(Goodsman goodsman) {
		this.getHibernateTemplate().update(goodsman);
	}
}
